-
Notifications
You must be signed in to change notification settings - Fork 287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Function calls #507
Function calls #507
Conversation
df96ee4
to
1602786
Compare
napi automatically wraps and unwraps the `data` pointer on functions created through `napi_create_function`, so we don't need to use the `napi_create_external` API in neon-runtime. Instead we can work with the raw pointers. This aligns the C++ and n-api APIs so that the `neon` crate can just assume associated data for a function is always a raw pointer.
napi expects you to return a `napi_value` from your functions, instead of using `SetReturn` like in nan. I ended up having to duplicate these `invoke` implementations after all!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is incredible, and so many tests, too! Thank you for this amazing PR.
I just made a few small suggestions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! We can ship as long as we get CI passing.
Looks like CI is passing, Travis just somehow isn't updating the PR. Merged! 🎉🎉🎉🎉🎉 |
Implements most simple function calls between Rust and JS code. (no thread-safe callbacks yet!) Builds on #493.
With function calls, we can start porting tests from the legacy runtime to n-api. I ported tests for objects and functions here.
There are some notable differences between NAN and n-api in how they deal with functions.
v8::External
value. n-api also unwraps it for you when you ask for the data pointer. To align the two runtimes, I moved the unwrapping of thev8::External
for the NAN runtime intoneon-sys
. Functions that were used to get data out from thev8::External
value now take void pointers.get_dynamic_callback()
is now a no-op but I left it in so the data format can be changed later.SetReturn()
to set the return value for a function call. With n-api, you can return annapi_value
from your functions instead. The n-api runtime gets its ownCallback
impl andneon_runtime::call::set_return
is unused.undefined
napi_value
.The
FunctionCallbackInfo
structure was one that could only be used as a reference. n-api has an opaquenapi_callback_info
type alias for a pointer, which could not be used in this way. I changedFunctionCallbackInfo
to be a pointer instead.FunctionCallbackInfo<'a>
, so we can't store it for longer than the actual function call lasts?